/*
 * EcmaScriptDumpVisitor.java - ScriptME
 * 
 * Copyright (c) 2009 Cesar Henriques <cesar at alttab.com.ar>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Based on FESI Project
 * 
 * Contributors:
 * 	Jean-Marc Lugrin - initial API and implementation
 * 	Cesar Henriques <cesar at alttab.com.ar> - J2ME Porting and Extensions
 */
/*
 * 
 */
package org.scriptme.ecmascript.ast;

// TODO: Auto-generated Javadoc
/**
 * The Class EcmaScriptDumpVisitor.
 */
public class EcmaScriptDumpVisitor implements EcmaScriptVisitor {

	/** The indent. */
	private int indent = 0;

	/**
	 * Indent string.
	 * 
	 * @return the string
	 */
	private String indentString() {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < indent; ++i) {
			sb.append(" ");
		}
		return sb.toString();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.SimpleNode,
	 *      java.lang.Object)
	 */
	public Object visit(SimpleNode node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTProgram,
	 *      java.lang.Object)
	 */
	public Object visit(ASTProgram node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTStatementList,
	 *      java.lang.Object)
	 */
	public Object visit(ASTStatementList node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTFunctionDeclaration,
	 *      java.lang.Object)
	 */
	public Object visit(ASTFunctionDeclaration node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTFormalParameterList,
	 *      java.lang.Object)
	 */
	public Object visit(ASTFormalParameterList node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTVariableDeclaration,
	 *      java.lang.Object)
	 */
	public Object visit(ASTVariableDeclaration node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTIfStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTIfStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTWhileStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTWhileStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTForStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTForStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTForInStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTForInStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTForVarStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTForVarStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTForVarInStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTForVarInStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTContinueStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTContinueStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTBreakStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTBreakStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTReturnStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTReturnStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTWithStatement,
	 *      java.lang.Object)
	 */
	public Object visit(ASTWithStatement node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTThisReference,
	 *      java.lang.Object)
	 */
	public Object visit(ASTThisReference node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTCompositeReference,
	 *      java.lang.Object)
	 */
	public Object visit(ASTCompositeReference node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTFunctionCallParameters,
	 *      java.lang.Object)
	 */
	public Object visit(ASTFunctionCallParameters node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTPropertyIdentifierReference,
	 *      java.lang.Object)
	 */
	public Object visit(ASTPropertyIdentifierReference node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTPropertyValueReference,
	 *      java.lang.Object)
	 */
	public Object visit(ASTPropertyValueReference node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTAllocationExpression,
	 *      java.lang.Object)
	 */
	public Object visit(ASTAllocationExpression node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTOperator,
	 *      java.lang.Object)
	 */
	public Object visit(ASTOperator node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTPostfixExpression,
	 *      java.lang.Object)
	 */
	public Object visit(ASTPostfixExpression node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTUnaryExpression,
	 *      java.lang.Object)
	 */
	public Object visit(ASTUnaryExpression node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTBinaryExpressionSequence,
	 *      java.lang.Object)
	 */
	public Object visit(ASTBinaryExpressionSequence node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTOrExpressionSequence,
	 *      java.lang.Object)
	 */
	public Object visit(ASTOrExpressionSequence node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTAndExpressionSequence,
	 *      java.lang.Object)
	 */
	public Object visit(ASTAndExpressionSequence node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTConditionalExpression,
	 *      java.lang.Object)
	 */
	public Object visit(ASTConditionalExpression node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTAssignmentExpression,
	 *      java.lang.Object)
	 */
	public Object visit(ASTAssignmentExpression node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTExpressionList,
	 *      java.lang.Object)
	 */
	public Object visit(ASTExpressionList node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTEmptyExpression,
	 *      java.lang.Object)
	 */
	public Object visit(ASTEmptyExpression node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTLiteral,
	 *      java.lang.Object)
	 */
	public Object visit(ASTLiteral node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.ast.EcmaScriptVisitor#visit(org.scriptme.ecmascript.ast.ASTIdentifier,
	 *      java.lang.Object)
	 */
	public Object visit(ASTIdentifier node, Object data) {
		System.out.println(indentString() + node);
		++indent;
		data = node.childrenAccept(this, data);
		--indent;
		return data;
	}

}
